package com.lwldjx.auth.domain.service.impl;

import cn.dev33.satoken.secure.SaSecureUtil;
import com.lwldjx.auth.common.enums.AuthUserStatusEnum;
import com.lwldjx.auth.common.enums.IsDeletedFlagEnum;
import com.lwldjx.auth.domain.convert.AuthRoleBOConverter;
import com.lwldjx.auth.domain.entity.AuthRoleBO;
import com.lwldjx.auth.domain.service.AuthRoleDomainService;
import com.lwldjx.auth.infra.basic.entity.AuthRole;
import com.lwldjx.auth.infra.basic.service.AuthRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {
    @Resource
    private AuthRoleService authRoleService;


    @Override
    public Boolean add(AuthRoleBO authRoleBo) {
        AuthRole authRole= AuthRoleBOConverter.INSTANCE.convertBOToEntity(authRoleBo);
        authRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        Integer count= authRoleService.insert(authRole);
        //建立一个初步的角色管理
        return count>0;
    }

    @Override
    public Boolean update(AuthRoleBO authRoleBo) {
        AuthRole authRole= AuthRoleBOConverter.INSTANCE.convertBOToEntity(authRoleBo);
        Integer count= authRoleService.update(authRole);//建立一个初步的角色管理
        return count>0;
    }

    @Override
    public Boolean delete(AuthRoleBO authRoleBo) {
        AuthRole authRole = new AuthRole();
        authRole.setId(authRoleBo.getId());
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        Integer count = authRoleService.update(authRole);
        //有任何的更新，都要与缓存进行同步的修改
        return count > 0;
    }

    @Override
    public Boolean deleteById(AuthRoleBO authRoleBo) {
        AuthRole authRole = new AuthRole();
        authRole.setId(authRoleBo.getId());
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        long id=authRole.getId();
        Boolean count = authRoleService.deleteById(id);
        //有任何的更新，都要与缓存进行同步的修改
        return count ;
    }
}
